package com.test.example.controller.excel.style;

import cn.afterturn.easypoi.excel.export.styler.AbstractExcelExportStyler;
import cn.afterturn.easypoi.excel.export.styler.IExcelExportStyler;
import com.xingluo.tools.excel.ExcelExportStyleUtils;
import org.apache.poi.ss.usermodel.*;

/**
 * 自定义样式
 */
public class ExcelExportStyler extends AbstractExcelExportStyler implements IExcelExportStyler {
    public ExcelExportStyler(Workbook workbook) {
        super.createStyles(workbook);
    }


    @Override
    public CellStyle getHeaderStyle(short headerColor) {
        CellStyle titleStyle = workbook.createCellStyle();
        // 设置字体
        titleStyle.setFont(ExcelExportStyleUtils.getFont(workbook, "微软雅黑",11, true));
        // 自定义背景色
        ExcelExportStyleUtils.setBackgroundColor(titleStyle, IndexedColors.LIGHT_YELLOW.getIndex());
        // 设置居中
        ExcelExportStyleUtils.setCenter(titleStyle);
        // 设置边框
        ExcelExportStyleUtils.setBorder(titleStyle);
        return titleStyle;
    }

    @Override
    public CellStyle getTitleStyle(short color) {
        CellStyle titleStyle = workbook.createCellStyle();
        // 设置字体
        titleStyle.setFont(ExcelExportStyleUtils.getFont(workbook, "微软雅黑", 12, true));
        // 自定义背景色
        ExcelExportStyleUtils.setBackgroundColor(titleStyle, IndexedColors.PALE_BLUE.getIndex());
        // 自定义背景色
        titleStyle.setFillForegroundColor(IndexedColors.PALE_BLUE.getIndex());
        titleStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        titleStyle.setWrapText(true);
        return titleStyle;
    }

    /*以下都是行样式，交替*/

    /**
     * 行样式
     */
    @Override
    public CellStyle stringSeptailStyle(Workbook workbook, boolean isWarp) {
        CellStyle style = workbook.createCellStyle();
        style.setDataFormat(STRING_FORMAT);
        style.setWrapText(isWarp);
        return style;
    }

    /**
     * 这里设置循环行，没有样式的一行
     */
    @Override
    public CellStyle stringNoneStyle(Workbook workbook, boolean isWarp) {
        CellStyle style = workbook.createCellStyle();
        style.setDataFormat(STRING_FORMAT);
        style.setWrapText(isWarp);
        return style;
    }
}


